package warehouse;

import java.util.HashMap;
import java.util.Map;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Accordion;
import javafx.scene.control.TitledPane;
import javafx.scene.paint.Color;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

public class SimpleHTMLswing extends Application
{
    
   private Accordion prepareAccordion(final Map<String, String> titleToUrl)
   {
      final Accordion accordion = new Accordion();
      for (final Map.Entry<String,String> webMap : titleToUrl.entrySet())
      {
         final TitledPane pane =
            new TitledPane(webMap.getKey(), buildWebView(webMap.getValue()));
         pane.setMinSize(1200, 600);
         accordion.getPanes().add(pane);
      }
      return accordion;
   }


   private WebView buildWebView(final String url)
   {
      final WebView webView = new WebView();
      webView.setMaxSize(1200, 600);
      webView.getEngine().load(url);
      return webView;
   }


   @Override
   public void start(final Stage stage) throws Exception
   {
      stage.setTitle("Database representation");
      final Group rootGroup = new Group();
      final Map<String,String> titleToUrl;
      titleToUrl = new HashMap<>();
      titleToUrl.put("Data base", "file:///"+Constants.HTMLS_ROOT+"collapsible.html");
      titleToUrl.put("Bubble view", "file:///"+Constants.HTMLS_ROOT+"index.html");
      titleToUrl.put("Tree Map", "file:///"+Constants.HTMLS_ROOT+"treemap.html");
      titleToUrl.put("Incasari firme", "file:///"+Constants.HTMLS_ROOT+"evolution.html");
                             
      rootGroup.getChildren().add(prepareAccordion(titleToUrl));
      rootGroup.setAutoSizeChildren(true);
      final Scene scene = new Scene(rootGroup, 1200, 800, Color.WHITE);
      stage.setScene(scene);
      stage.show();
   }


   public static void main(final String[] arguments)
   {
      Application.launch(arguments);
   }
}